from django.db import models
from django.forms import ModelForm
from tasktracker.managers import TaskManager, CategoryManager

INTERVAL_TYPES = {
    1: ('minutes', 60),
    2: ('hours', 3600),
    3: ('days', 86400),
    4: ('weeks', 604800),
}

STATUS_TYPES = (
    (1, 'Queued'),
    (2, 'Processing'),
    (3, 'Completed'),
    (4, 'Cancelled'),
    (5, 'Failed'),
)

# Category
class Category(models.Model):
    code = models.CharField('Code', max_length=15, unique=True)
    description = models.CharField('Description', max_length=255)

    objects = CategoryManager()
    
    def __unicode__(self):
        return self.code


# Category Form
class CategoryForm(ModelForm):
    class Meta:
        model = Category

            
# Task
class Task(models.Model):
    description = models.TextField('Description', max_length=255, unique=True)
    category = models.ForeignKey(Category)
    status = models.IntegerField('Status', choices=STATUS_TYPES)
    opened = models.DateTimeField();
    closed = models.DateTimeField(blank=True, null=True);

    objects = TaskManager()
    
    def __unicode__(self):
        return self.description
        
        
# Task Form
class TaskForm(ModelForm):
    class Meta:
        model = Task
        fields = ('description', 'category', 'status', 'opened')
            
        
# Time Log
class TimeLog(models.Model):
    start = models.DateTimeField('Start')
    end = models.DateTimeField('End')
    status = models.IntegerField('Status', choices=STATUS_TYPES)
    task = models.ForeignKey(Task)
    

